<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>修改标题</title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 
  
</head>

<body>
    <div class="container">
        <h1>修改标题</h1>
        <hr>
        <div class="col-sm-6">


               <div class="form-group">
                <label>请修改标题</label>
                <input type="text" class="form-control" name="title" id="title" placeholder="请修改标题">
            </div>
           
            <button type="submit" class="btn btn-success" onclick="ok()">确认修改</button>
            <a href="index.html" type="submit" class="btn btn-default ">返回</a>
         

            
        </div>
    </div>
    <script src="jquery-1.12.4.js"></script>
    <script>
    var url = "https://shenyuxf.top/";

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    // 调用方法
    var _id = GetQueryString("_id");

   
   console.log(_id)

  
       //拿到相对的id 的值
    $.ajax({
        url: url + 'title?_id=' + _id,
        type: 'GET',
        success: (data) => {    
            $("#title").val(data[0].title)      
              

        },
        dataType: 'json',
        error: (xhr, status, error) => {

        }
    })

  // 确认修改

    function ok() {

        var title = $("#title").val();
      
        $.ajax({
            url: `${url}updatetitle?_id=${_id}&title=${title}`,
            type: 'GET',
            success: (data) => {
                alert("修改成功")
                window.location = "index.html"
            },
            dataType: 'text',
            error: (xhr, status, error) => {
                console.log(status)
            }
        })

    }

       


 
    </script>
</body>

</html>
